package com.huxin.servelt;

import com.huxin.pojo.BookTypeInfo;
import com.huxin.service.Userservice;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/addbooktype")
public class AddBookTypeServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取请求方法
        request.setCharacterEncoding("utf-8");
        //处理响应乱码
        response.setContentType("text/json;charset=utf-8");
        String name=request.getParameter("name");
        BookTypeInfo type = new BookTypeInfo();
        type.setName(name);
        Userservice service = new Userservice();
        int i=service.Addtype(type);
        if (i>0){
            response.sendRedirect("http://localhost:8080/web/html/admin/book_class_list2.html");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
